<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="js/vue.js"></script>
    <title>Document</title>
</head>
<body>
    <div id="app">
        <input type="text" v-model="inputVal">
        <button @click="add">添加</button>
        <div v-if="needToDo.length === 0">列表为空</div>
        <ul v-else>
            <li v-for="item,index in needToDo">
                {{ item }} --- <button @click="remove(index)">删除</button>
            </li>
        </ul>
        
    </div>
    <script>
        var vm = new Vue({
            el:"#app",
            data:{
                inputVal:"",
                needToDo:[1,2,3]
            },
            methods:{
                add(){
                   this.needToDo.push(this.inputVal)
                },
                remove(index){
                    this.needToDo.splice(index, 1)
                }
            }
        });
    </script>
</body>
</html>